<template>
  <div class="login-container">
    <div class="login-wrapper">
      <div class="ad">
        <img src="../../assets/logo.png">
      </div>
      <div class="login-box">
        <h2 class="login-title">欢迎登录</h2>
        <el-form ref="form" status-icon :rules="rules" :model="form">
          <el-form-item prop="username">
            <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item prop="password" class="mb10">
            <el-input type="password" v-model="form.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-checkbox v-model="form.rememberMe">记住我</el-checkbox>
            <a class="forgot-password">忘记密码？</a>
          </el-form-item>
          <el-form-item class="center">
            <el-button type="primary" style="width:98%" @click="handleLogin">登 录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: undefined,
        password: undefined,
        rememberMe: false
      },
      rules: {
        username: [{required: true, message: '请输入用户名'}],
        password: [{required: true, message: '请输入密码'}]
      }
    };
  },
  methods: {
    handleLogin() {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          this.$message.error('请正确填写参数');
          return false;
        }
        // TODO 登录逻辑 ...
        localStorage.setItem('Authorization', 'xxx')
        this.$router.push('/');
      });
    }
  }
};
</script>

<style scoped>
.login-container {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f7fafc;
  background: linear-gradient(to left top, #a0ffdd, #6144fe);
}

.login-wrapper {
  width: 768px;
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 0 0 10px rgba(0, 0, 0, .1);
  display: flex;
  border-radius: 8px;
}

.ad {
  flex: 1;
  padding: 50px 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.ad::after {
  content: '';
  display: block;
  height: 70%;
  border-right: 1px solid #eee;
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}

.login-box {
  flex: 1;
  padding: 50px 50px;
}

.login-title {
  font-size: 24px;
  margin-bottom: 30px;
  text-align: center;
}

/*.login-title::before {
  content: '{';
  color: #eee;
  margin-right: 10px;
}

.login-title::after {
  content: '}';
  color: #eee;
  margin-left: 10px;
}*/

.forgot-password {
  float: right;
  color: #999;
  text-decoration: none;
}

.center {
  text-align: center;
}

.mb10 {
  margin-bottom: 10px;
}

@media (max-width: 767px) {
  .login-wrapper {
    width: 100%;
  }

  .ad {
    display: none;
  }
}
</style>